package com.diandian.backend.kuaishou.life.exchange.controller;

import com.diandian.backend.kuaishou.life.exchange.service.BusinessTokenGetService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.kuaishou.life.boot.starter.param.ProductPageQueryParam;
import com.diandian.kuaishou.life.boot.starter.service.KuaiShouLifeOrderBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private KuaiShouLifeOrderBasicService orderService;

    @Autowired
    private BusinessTokenGetService businessTokenGetService;

    /**
     * 查询订单列表
     */
    @PostMapping( "/page/get")
    public BaseResult getOrderPage(@RequestHeader(name = "appKey") String appKey,
                                   @RequestHeader(name = "appSecret") String appSecret,
                                   @RequestHeader(value = "merchantId") String merchantId,
                                   @RequestBody ProductPageQueryParam param) {
        String accessToken = businessTokenGetService.getToken(appKey, appSecret, merchantId);
        return new BaseResult(0, "success", orderService.getOrderPage(accessToken, param));
    }

    /**
     * 查询订单详情
     */
    @PostMapping( "/detail/get")
    public BaseResult getOrderDetail(@RequestHeader(name = "appKey") String appKey,
                                     @RequestHeader(name = "appSecret") String appSecret,
                                     @RequestHeader(value = "merchantId") String merchantId,
                                     @RequestParam(value = "orderId") String orderId) {
        String accessToken = businessTokenGetService.getToken(appKey, appSecret, merchantId);
        return new BaseResult(0, "success", orderService.getOrderDetail(accessToken, orderId));
    }

}
